﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JibberJabber.PartDesigners;

namespace JibberJabber.Controls
{
    public class AddChildMenuItem : ToolStripMenuItem
    {
        PartDesigner rootDesigner;
        Type childDesignerType;

        public AddChildMenuItem(PartDesigner rootPd, Type designerType) : base()
        {
            this.rootDesigner = rootPd;
            this.childDesignerType = designerType;
            this.Text = GetFriendlyDesignerName(designerType);
            this.Tag = designerType;
            this.Click += new EventHandler(AddChildMenuItem_Click);
        }

        private void AddChildMenuItem_Click(object sender, EventArgs e)
        {
            Program.AddChildPartDesigner(rootDesigner, (PartDesigner)Activator.CreateInstance(childDesignerType));
        }

        public static string GetFriendlyDesignerName(Type designerType)
        {
            if (designerType == typeof(RootNodeDesigner))
                return "Root Node";
            else if (designerType == typeof(SpeakerDesigner))
                return "Speaker";
            else if (designerType == typeof(SpeakersNodeDesigner))
                return "Speakers List";
            else if (designerType == typeof(TextPartDesigner))
                return "Text";
            else
                return designerType.ToString() + " (Program.GetFriendlyDesignerName() has no matches!)";
        }
    }
}
